package com.weibo.dip.docker;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.Image;
import com.github.dockerjava.core.DockerClientBuilder;

import java.util.List;

/** Created by haisen on 2018/6/25. */
public class DockerImageexit {

  private static DockerClient dockerClient = DockerClientBuilder.getInstance().build();

  public static boolean imageExit(String imagename, String imagetag) {
    List<Image> images = dockerClient.listImagesCmd().exec();
    String name = imagename + ":" + imagetag;
    for (Image image : images) {
      String[] infos = image.getRepoTags();
      for (String info : infos) {
        if (info.equals(name)) {
          return true;
        }
      }
    }
    return false;
  }

  public static void main(String[] args) {
    String imagename = "shixi_dongxue/test";
    String imagetag = "v1";

    if (DockerImageexit.imageExit(imagename, imagetag)) {
      System.out.println("Exit image " + imagename + ":" + imagetag);
    }
  }
}
